//
//  RHBatteryCellItemCell2.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/27.
//

#import "RHBatteryCellItemCell2.h"
@interface RHBatteryCellItemCell2()
@property (nonatomic, strong) UIImageView *batteryImg;

@property (nonatomic, strong) UIImageView *arrowImg;


@property (nonatomic, strong) QMUILabel *temperatureContentLab;

@property (nonatomic, strong) QMUILabel *voltageContentLab;

@property (nonatomic, strong) QMUILabel *resistanceContentLab;

@property (nonatomic, strong) UIView *bgView;
@end
@implementation RHBatteryCellItemCell2

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}

-(void)setCellModel:(RHDevCellModel *)cellModel
{
    _cellModel = cellModel;
    if(cellModel.status == 0){
        self.batteryImg.image = [UIImage imageNamed:@"dev_me_cell_normal"];;
        
        self.arrowImg.image = nil;
    }else if(cellModel.status == 1){
        self.batteryImg.image = [UIImage imageNamed:@"dev_me_cell_high"];;
        
        self.arrowImg.image = [UIImage imageNamed:@"battery_temperature_high_arrow"];
    }else{
        self.batteryImg.image = [UIImage imageNamed:@"dev_me_cell_low"];;
        
        self.arrowImg.image = [UIImage imageNamed:@"battery_temperature_low_arrow"];
    }
    self.temperatureContentLab.text = [NSString stringWithFormat:@"%@%@",cellModel.temp,@"℃"];
    self.voltageContentLab.text = [NSString stringWithFormat:@"%@%@",cellModel.volt,@"mV"];
    self.resistanceContentLab.text = [NSString stringWithFormat:@"%@%@",ValidNullDataToString(cellModel.resistance, @"--"),@"mΩ"];
   
}

-(void)setupUI
{
    kWeakSelf;
    self.contentView.backgroundColor = CFTabViewBgColor;
    UIView *bgView = kView;
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    self.bgView = bgView;
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    
    _batteryImg = [[UIImageView alloc]init];
    [bgView addSubview:_batteryImg];
    [_batteryImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.top.mas_offset(5);
        make.width.height.offset(20);
    }];
    
    _packNoLab = [[QMUILabel alloc]init];
    _packNoLab.text = @"PACK 1#";
    _packNoLab.font = [UIFont systemFontOfSize:13];
    _packNoLab.textAlignment = NSTextAlignmentLeft;
    _packNoLab.textColor = kCOLOR_HEX(@"3F4443");
    [bgView addSubview:_packNoLab];
    [_packNoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.batteryImg.mas_right).offset(5);
        make.centerY.equalTo(weakSelf.batteryImg);
        make.height.offset(20);
    }];
    
    QMUIButton *chartBtn = [[QMUIButton alloc]init];
    [chartBtn setImage:[UIImage imageNamed:@"device_cell_chart"] forState:UIControlStateNormal];
    [bgView addSubview:chartBtn];
    [chartBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-5);
        make.width.height.offset(35);
        make.centerY.equalTo(weakSelf.packNoLab);
    }];
    
    [[chartBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.chartBlock){
            weakSelf.chartBlock();
        }
    }];
    
    UIView *line = kView;
    line.backgroundColor = kCOLOR_HEX(@"E7E7E7");
    [bgView addSubview:line];
    
    
    
    //温度
    QMUILabel *temperatureTitleLab = [[QMUILabel alloc]init];
    temperatureTitleLab.text = [NSString stringWithFormat:@"%@:",@"温度".rh_localized];
    temperatureTitleLab.font = [UIFont systemFontOfSize:13];
    temperatureTitleLab.textAlignment = NSTextAlignmentLeft;
    temperatureTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    [bgView addSubview:temperatureTitleLab];
    
    _temperatureContentLab = [[QMUILabel alloc]init];
    _temperatureContentLab.text = @"--℃";
    _temperatureContentLab.font = [UIFont systemFontOfSize:11];
    _temperatureContentLab.textAlignment = NSTextAlignmentRight;
    _temperatureContentLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.8];
    [bgView addSubview:_temperatureContentLab];
    
    //电压
    QMUILabel *voltageTitleLab = [[QMUILabel alloc]init];
    voltageTitleLab.text = [NSString stringWithFormat:@"%@:",@"电压".rh_localized];
    voltageTitleLab.font = [UIFont systemFontOfSize:11];
    voltageTitleLab.textAlignment = NSTextAlignmentLeft;
    voltageTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    [bgView addSubview:voltageTitleLab];
    
    _voltageContentLab = [[QMUILabel alloc]init];
    _voltageContentLab.text = @"--mV";
    _voltageContentLab.font = [UIFont systemFontOfSize:11];
    _voltageContentLab.textAlignment = NSTextAlignmentRight;
    _voltageContentLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.8];
    [bgView addSubview:_voltageContentLab];
    
    
    _arrowImg = [[UIImageView alloc]init];
    [bgView addSubview:_arrowImg];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(weakSelf.batteryImg);
        make.right.mas_offset(-10);
        make.top.equalTo(weakSelf.packNoLab.mas_bottom).offset(5);
        make.height.offset(1);
    }];
    
    

    [temperatureTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(line.mas_bottom).offset(15);
        make.left.mas_offset(10);
        make.right.equalTo(weakSelf.temperatureContentLab.mas_left).offset(-5);
    }];
    
    
    [_temperatureContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-10);
        make.centerY.equalTo(temperatureTitleLab);
        make.width.greaterThanOrEqualTo(@(50));
    }];
    
    [_arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.temperatureContentLab.mas_left).offset(-3);
        make.centerY.equalTo(weakSelf.temperatureContentLab);
        make.size.equalTo(@(CGSizeMake(10, 10)));
    }];
    
    [voltageTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(temperatureTitleLab);
        make.bottom.mas_offset(-15);
        make.right.equalTo(weakSelf.voltageContentLab.mas_left).offset(-5);
    }];
    
    [_voltageContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.temperatureContentLab);
        make.centerY.equalTo(voltageTitleLab);
        make.width.greaterThanOrEqualTo(@(50));
    }];
    
  
    
}
@end
